package org.kjtc.mapper;

import org.apache.ibatis.annotations.*;
import org.kjtc.entity.*;

import java.util.List;

/**
 * Created by qwre on 2017/12/5.
 */
@Mapper
public interface ProductMapper {

    @Select("select m.ModuleID, m.ModuleName,sp.SprintName,sp.SprintNameSign from module m \n" +
            "left join productversion v on v.ProductVersionID = m.ProductVersionID\n" +
            "left join product p on p.ProductID = v.ProductID\n" +
            "left join backlog b on m.ModuleID = b.ModuleID\n" +
            "left join worktype w on b.WorkTypeID = w.WorkTypeID\n" +
            "left join userinfo u on u.UserID = m.UserID\n" +
            "left join sprint sp on sp.SprintID = m.SprintID "+
            "where v.ProductVersionID  = #{ProductVersionID} and v.ProductID= #{ProductID} \n" +
            "GROUP BY m.ModuleID\n" +
            "order BY b.CreateDTTM desc")
    List<BackLog> getProductModuleID(BackLog backLog);

    @Select("SELECT ProductVersionDescription FROM productversion where ProductVersionID = #{ProductVersionID}")
    List<BackLog> getDescriptionMsg(BackLog backLog);

    @SelectProvider(type =AllProvider.class, method = "getVersionDetalis")
    List<BackLog> getVersionDetalisMsg(BackLog backLog);

    @SelectProvider(type =AllProvider.class, method = "getFeedBackDetalis")
    List<FeedBack> getModuleBackDetalis(FeedBack feedBack);

    @Insert("insert into productversion (" +
            "ProductVersionID," +
            "ProductVersionName," +
            "ProductID," +
            "ProductVersionDescription," +
            "CreateUser," +
            "CreateDTTM," +
            "UpdateUser," +
            "UpdateDTTM" +
            ") values (" +
            "#{ProductVersionID}," +
            "#{ProductVersionName}," +
            "#{ProductID}," +
            "#{ProductVersionDescription}," +
            "#{CreateUser}," +
            "SYSDATE()," +
            "#{UpdateUser}," +
            "SYSDATE()" +
            ")")
    int addVersionsMsg(ProductVersion productVersion);

    @Delete("delete from productversion where ProductID = #{ProductID} and ProductVersionID = #{ProductVersionID}")
    int delVersionsMsg(ProductVersion productVersion);

    @Update("update " +
            "module " +
            "set " +
            "UpdateUser = #{UpdateUser}," +
            "UpdateDTTM = SYSDATE()," +
            "ModuleName = #{ModuleName}" +
            "where " +
            "ModuleID = #{ModuleID} and ProductVersionID = #{ProductVersionID}")
    int updateModuleName(Module module);

    @Delete("delete from module where ModuleID = #{ModuleID} and ProductVersionID = #{ProductVersionID}")
    int deletModuleID(Module module);

    @Insert("insert into backlog (" +
            "ModuleID," +
            "BackLogID," +
            "BackLogStatus," +
            "WorkTypeID," +
            "BackLogName," +
            "UserID," +
            "ExpectedWorkDate," +
            "ExpectedStartDTTM," +
            "ExpectedEndDTTM," +
            "CreateUser," +
            "CreateDTTM," +
            "UpdateUser," +
            "UpdateDTTM" +
            ") values (" +
            "#{ModuleID}," +
            "#{BackLogID}," +
            "#{BackLogStatus}," +
            "#{WorkTypeID}," +
            "#{BackLogName}," +
            "#{UserID}," +
            "#{ExpectedWorkDate}," +
            "#{ExpectedStartDTTM}," +
            "#{ExpectedEndDTTM}," +
            "#{CreateUser}," +
            "SYSDATE()," +
            "#{UpdateUser}," +
            "SYSDATE()" +
            ")")
    int addBackLogMsgSure(BackLog backLog);

    @Insert("insert into feedback(" +
            "FeedBackID," +
            "ModuleID," +
            "FeedBackStatus," +
            "FeedBackDescription," +
            "FeedBackUser," +
            "CreateUser," +
            "CreateDTTM," +
            "UpdateUser," +
            "UpdateDTTM" +
            ") values (" +
            "#{FeedBackID}," +
            "#{ModuleID}," +
            "#{FeedBackStatus}," +
            "#{FeedBackDescription}," +
            "#{FeedBackUser}," +
            "#{CreateUser}," +
            "SYSDATE()," +
            "#{UpdateUser}," +
            "SYSDATE()" +
            ")")
    int addFeedBackMsgSure(FeedBack feedBack);

    @Update("update " +
            "productversion " +
            "set " +
            "UpdateUser = #{UpdateUser}," +
            "UpdateDTTM = SYSDATE()," +
            "ProductVersionName = #{ProductVersionName}," +
            "ProductVersionDescription = #{ProductVersionDescription}" +
            "where " +
            "ProductID = #{ProductID} and ProductVersionID = #{ProductVersionID}")
    int updateVersionsMsg(ProductVersion productVersion);

    @Insert("insert into product (" +
            "ProductId," +
            "ProductName," +
            "UserID," +
            "CreateUser," +
            "CreateDTTM," +
            "UpdateUser," +
            "UpdateDTTM" +
            ") values (" +
            "#{ProductId}," +
            "#{ProductName}," +
            "#{UserID}," +
            "#{CreateUser}," +
            "SYSDATE()," +
            "#{UpdateUser}," +
            "SYSDATE()" +
            ")")
    int saveNewProject(Product product);

    @Insert("insert into module (" +
            "ModuleID," +
            "ModuleName," +
            "ProductVersionID," +
            "SprintID," +
            "CreateUser," +
            "CreateDTTM," +
            "UpdateUser," +
            "UpdateDTTM" +
            ") values (" +
            "#{ModuleID}," +
            "#{ModuleName}," +
            "#{ProductVersionID}," +
            "#{SprintID}," +
            "#{CreateUser}," +
            "SYSDATE()," +
            "#{UpdateUser}," +
            "SYSDATE()" +
            ")")
    int  addModuleID(Module module);

    @Select("SELECT SprintID,SprintName FROM sprint WHERE ProductVersionID=#{productVersionID} ORDER BY SprintName")
    public List<Sprint> getAllSprint(String productVersionID);

    @Delete("DELETE FROM product WHERE productID = #{productID}")
    int deleteProduct(String productID);

    @Update("update product set ProductName = #{ProductName} where ProductID=#{ProductId}")
    int doUpdateProductName(Product product);

}
